import turtle

# 初始化位置
points = [[-50, 0], [0,0], [50,0], [100, 0]]

def move():
    """小球的移动更新"""
    turtle.clear()
    is_running = True

    for i in range(len(points)):
        turtle.up()
        turtle.goto(points[i])
        turtle.down()
        turtle.dot(30, 'gold')
        points[i][1]-=3
        if points[i][1]> 320 or points[i][1]< -320:
            print('---》', points[i])
            is_running = False
    if is_running:
        turtle.ontimer(move, 100)


def func_click():
    """键盘的监听函数"""
    global cur_index
    points[cur_index][1]+=40
    cur_index+=1
    if cur_index>3:
        cur_index = 0

turtle.tracer(False)
cur_index = 0
move()
# turtle.onscreenclick(func_click)
# 键盘监听函数
turtle.onkeypress(func_click)
# 开始监听
turtle.listen()
turtle.done()